<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>封装函数</title>
    <style>
        .div{
            border:1px solid;
            width:40px;
            height:40px; 
            padding-left:20px; 
       }
        .div2{
            border:1px solid;
            width:40px;
            height:40px; 
            padding-left:20px; 
       }
    </style>
</head>
<body>
    <h1>封装函数</h1>
    <hr>
    <input type="text" class="div" id="input">
    <div class="div2" id="div"></div>
    <button onclick="Factorials()">提交</button>
    <hr>

    

<script>
    
    // 获取一个随机数;
    // 1-11 之间的随机数
    document.write(Math.random());
    // 1. 生成一个包含min 不包含 max 的整数;
    console.log(parseInt(Math.random() * 10 + 1,10));
    
    function randAll(max,min,left=1,right=1){

        if (left == 1 && right == 1) {
            console.log('第一');
          return  Math.round(Math.random() * (max-min)+min);
        }
        if (left == 1 && right !== 1) {
            console.log('第二');
          return  parseInt(Math.random() * (max-min) + min, 10);
        }
        if (left !== 1 && right !== 1) {
            console.log('第三');
          return  Math.round(Math.random() * (max-min) + min +1);
        }
        if (left !== 1 && right == 1) {
            console.log('第四');
          return  Math.floor(Math.random() * (max-min) + min) + 1;
        }
        


    }

    console.log(randAll(1,10));
    console.log(randAll(1,10,0,0));
    console.log(randAll(1,10,1,0));
    console.log(randAll(1,10,0,1));
// --------------------------------------------------------------------------------
    // 阶乘
    // 
    function Factorials(){
        var counts = 0;
        var num = document.getElementById('input').value;
        console.log(num);

         function Factorial(num){
            if (num<0) {return alert('不得小于零!');}
            if (num==0) {return alert('不得等于零!');}
            if (num == 1) {
                return num;
            }
            
            var count = num * (num-1);
            var counts = Factorial(num-1);
            if (!counts) {
                counts = 1;
            }
            count *= counts;
            count /= num-1
            return count;


        }
              document.getElementById('div').innerHTML = Factorial(num);




    }
   



</script>  
    

</body>
</html>